package com.apes.fn.scm.retailOrder.model;

import com.apes.fn.crm.customerExpand.FnCustomerExpand;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import com.apes.scm.masterdata.product.model.ServeType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @program: apes-server
 * @description
 * @author: czs
 * @create: 2022-01-06 11:23
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(OverDiscountItem.class)
@Table(name = OverDiscountItem.CONST_TABLE_NAME)
public class OverDiscountItem extends Model {

    public static final String CONST_TABLE_NAME = "over_discount_item";

    @Id
    @Column(name = "id")
    @Comment("超额抵扣明细编码")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "超额抵扣明细编码")
    private String id;

    @Column(name = "source_business_type_name", nullable = false)
    @Comment("来源单据类型")
    private String sourceBusinessTypeName;

    @Column(name = "source_business_key", nullable = false)
    @Comment("来源单据号码")
    private String sourceBusinessKey;

    @Column(name = "source_business_date", nullable = false)
    @Comment("源单据创建日期")
    private Date sourceBusinessDate;

    @Comment("部门")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false)
    private Dept dept;

    @Comment("公司")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id", nullable = false)
    private PartyRole company;  //

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    @Comment("商品")
    private Product product;

    @Column(name = "sale_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("销售数量")
    private double saleQty = 0;

    @Column(name = "price_in_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("含税单价")
    private double priceInTax = 0;

    @Column(name = "price_in_tax_total", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("含税金额")
    private double priceInTaxTotal = 0;

    @Column(name = "refer_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("成本金额")
    private double referTax = 0;

    @Column(name = "discount_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("折扣金额")
    private double discountPrice = 0;

    @Column(name = "amt_profit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("毛利")
    private double amtProfit = 0;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位编码")
    private ProductUom uom;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id", nullable = false)
    @Comment("税率")
    private Tax tax;

    @Column(name = "price_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("税金")
    private double priceTax = 0;

    @Column(name = "price_subtotal", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("未含税金额")
    private double priceSubtotal = 0;

    @Comment("服务类型")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "serve_type_id", referencedColumnName = "id", nullable = false)
    private ServeType serveType;


    @Comment("会员扩展信息")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_expand_id", referencedColumnName = "id")
    private FnCustomerExpand customerExpand;
}
